package tv.accedo.achi.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SessionFactoryUtil {

	private static ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
	private static SessionFactory sessionFactory = (SessionFactory)ctx.getBean("sessionFactory");
	
	public static void setSessionFactory(SessionFactory sessionFactory) {
		SessionFactoryUtil.sessionFactory = sessionFactory;
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	public static void closeSession(Session session) {
		if (session != null) {
			if (session.isOpen()) {
				session.close();
			}
		}
	}
}
